package roborally.model;

import be.kuleuven.cs.som.annotate.*;
import roborally.model.interfaces.*;
/**
 *	@Invar 	|EnergyAmount.isValidEnergy(getEnergy(),getMaxEnergy())
 *	@Invar	|isValidWeight(getWeight())
 *	@Extends Item
 *	@Implements Terminatable
 *	@Implements EnergyHolder
 *
 */
public abstract class EnergyItem extends Item implements Terminatable, EnergyHolder {
	/**
	 * Constructor of an EnergyItem
	 * @pre		EnergyAmount.isValidEnergy(initialEnergy, maxEnergy)
	 * @param 	weight
	 * @param 	initialEnergy
	 * @param 	maxEnergy
	 */
	@Model
	protected EnergyItem(int weight, EnergyAmount initialEnergy, EnergyAmount maxEnergy){
		super(weight);
		setEnergy(initialEnergy);
		setMaxEnergy(maxEnergy);
	}

	/**
	 * Returns the maximum energy level of an EnergyItem object
	 * @return myMaxEnergy
	 */
	@Basic @Raw
	public EnergyAmount getMaxEnergy(){ return myMaxEnergy; }
	
	/**
	 * Sets the maximum energy level of an EnergyItem at maxEnergy
	 * @param 	maxEnergy
	 * 		  	The maximum energy level of an EnergyItem
	 * @post
	 *			|new.getMaxEnergy() == maxEnergy
	 */
	@Basic @Raw
	public void setMaxEnergy(EnergyAmount maxEnergy){ myMaxEnergy = maxEnergy; }
	
	/**
	 * Returns the energy level of an EnergyItem object
	 * @return myEnergy
	 */
	@Basic @Raw
	public EnergyAmount getEnergy(){ return myEnergy; }
	
	/**
	 * Sets the energy level of the EnergyItem at energy
	 * @pre		
	 * 			|EnergyAmount.isValidEnergy(energy, getMaxEnergy())
	 * @param energy
	 * @effect
	 * 			|getEnergy() == energy
	 */
	@Basic @Raw
	public void setEnergy(EnergyAmount energy){
		assert( EnergyAmount.isValidEnergy(energy, getMaxEnergy()) );
		myEnergy = energy; 
	}
	
	/**
	 * An EnergyAmount object indicating the energy level of an EnergyItem
	 */
	private EnergyAmount myEnergy;
	
	/**
	 * An EnergyAmount object indicating the maximum energy level of an EnergyItem
	 */
	private EnergyAmount myMaxEnergy;
	
}
